#include "ChallengeItem.h"
#include "../../model/proxy/ChanllengeProxy.h"
#include "../../net/NetController.h"

ChallengeItem::ChallengeItem(void)
	:mName(NULL),mLevel(NULL),mAttack(NULL),mDefense(NULL)
{
}

ChallengeItem::~ChallengeItem(void)
{
	CC_SAFE_RELEASE(mName);
	CC_SAFE_RELEASE(mLevel);
	CC_SAFE_RELEASE(mAttack);
	CC_SAFE_RELEASE(mDefense);
}

bool ChallengeItem::init()
{
	return true;
}

SEL_MenuHandler ChallengeItem::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	return NULL;
}

SEL_CCControlHandler ChallengeItem::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onChallengeBtnClick", ChallengeItem::onChallengeBtnClick);
	return NULL;
}

bool ChallengeItem::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName", CCLabelTTF *, this->mName);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mLevel", CCLabelTTF *, this->mLevel);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAttack", CCLabelTTF *, this->mAttack);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mDefense", CCLabelTTF *, this->mDefense);
	return false;
}

void ChallengeItem::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{

}

void ChallengeItem::onEnter()
{
	CCNode::onEnter();
}

void ChallengeItem::onExit()
{
	CCNode::onExit();
}

void ChallengeItem::refresh()
{
	ChallengeEnemyInfo* challengeEnemyInfo = (ChallengeEnemyInfo*)mData;
	mName->setString(challengeEnemyInfo->name.c_str());
	mLevel->setString(fcs("%d", challengeEnemyInfo->level));
	mAttack->setString(fcs("%d-%d", challengeEnemyInfo->atkMin, challengeEnemyInfo->atkMax));
}

void ChallengeItem::_onNotification( CCObject* object )
{
	
}

void ChallengeItem::onChallengeBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	ChallengeEnemyInfo* challengeEnemyInfo = (ChallengeEnemyInfo*)mData;
	ChanllengeProxy::getSingletonPtr()->curChallengeEnemyInfo = challengeEnemyInfo;
	Framework::getSingletonPtr()->popup("ChallengePreviewDialog");
}
